#ifndef CMM_OPERATION_H
#define CMM_OPERATION_H
#include <ostream>
#include "./definition.h"
#include "./memory.h"
#include "./location.h"
pw read_word(int point){
	pw t;t.s_p=point;
	if(!((file[point]>='a'&&file[point]<='z')||
	(file[point]>='A'&&file[point]<='Z')||file[point]=='_'
	||file[point]=='-'||(file[point]>='0'&&file[point]<='9'))){
		t.word=file[point];
		t.e_p=point+1;
		return t;
	}
	while((file[point]>='a'&&file[point]<='z')||
	(file[point]>='A'&&file[point]<='Z')||file[point]=='_'
	||file[point]=='-'||(file[point]>='0'&&file[point]<='9')){
		t.word+=file[point];
		point++;
	}
//	point--;
	t.e_p=point;
	return t;
}
pw read_string(int point){//read a string
	pw str_n;str_n.word="";str_n.s_p=point;
	while(file[point]!='\"'){
		point++;
	}
	point++;
	while(file[point]!='\"'){
		if(file[point]=='\\'){
			point++;
			if(file[point]=='\\')str_n.word+="\\";
			else if(file[point]=='\'')str_n.word+="\'";
			else if(file[point]=='\"')str_n.word+="\"";
			else if(file[point]=='n')str_n.word+="\n";
			else if(file[point]=='t')str_n.word+="\t";
		}
		else str_n.word+=file[point];
		point++;
		if(point>length_of_file)prog_error(point,8);
	}
	point++;
	str_n.e_p=point;
	return str_n;
}
pw read_char(int point){//read a char
	pw str_n;str_n.word="";str_n.s_p=point;
	while(file[point]!='\''){
		point++;
	}
	point++;
	while(file[point]!='\''){
		if(file[point]=='\\'){
			point++;
			if(file[point]=='\\')str_n.word+="\\";
			else if(file[point]=='\'')str_n.word+="\'";
			else if(file[point]=='\"')str_n.word+="\"";
			else if(file[point]=='n')str_n.word+="\n";
			else if(file[point]=='t')str_n.word+="\t";
		}
		else str_n.word+=file[point];
		point++;
		if(point>length_of_file)prog_error(point,8);
	}
	point++;
	str_n.e_p=point;
	return str_n;
}
void assignment(value_wtype &value,long long ava){
	if(value.type=="int"){
		value.int_type=ava;
	}
}
void assignment(value_wtype &value,char ava){
	if(value.type=="char"){
		value.char_type=ava;
	}
}
void assignment(value_wtype &value,std::string ava){
	if(value.type=="string"){
		value.string_type=ava;
	}
}
#endif /*!H*/
